<?php
class My_GalleryController extends MM_Controller_My_Action
{	
	public function indexAction(){
		$this->helper->setPageView($this->pageview, WEB_TITLE, "gallery", null);
	}
	
	public function getAction(){
		if ( $this->eid<1 ) {
			$this->result = $this->returnResult(Mediad2_Model_Result::CODE_FAILURE,'Miss parameter: eid');
		} else {
			$file = new MM_Service_Admin_EventFiles();
			$event = new MM_Service_Admin_Event();
			
			$where = sprintf("eid = '%s' AND status != '3'",$this->eid);
			$order = "addtime desc";
			$r1 = $file->fetchAll(1,999,$where,$order,true);
			$r2 = $event->find($this->eid,true);
			
			$data['photo'] = $r1->getData();
			$data['event'] = $r2->getData();
			$this->returnResult(1,"all",$data);
		}
		echo $this->encodeResult($this->result);
		
	}
	
	public function handleAction(){
		$fid 	= $this->httpdata['fid'];
		$fn 	= $this->httpdata['fn'];	//pause/del
		$ispause= $this->httpdata['ispause'];
		if ( $this->eid<1 || !isset($fid) || empty($fid) || !isset($fn) || empty($fn)) {
			$this->result = $this->returnResult(Mediad2_Model_Result::CODE_FAILURE,'Miss parameter: eid/fid/function');
		} else {
			$file = new MM_Service_Admin_EventFiles();					
			$where = sprintf("eid = '%s' AND fid = '%s'",$this->eid,$fid);
			$r1 = $file->findBy($where);		
			if($r1->getCode()){
				$model = $r1->getData();
				if(!$model->getFid()){
					$this->result= $this->returnResult(0,"null file");					
				}else{
					if($fn=="del")
						$model->setStatus(3);
					if($fn=="pause"){
						if(!isset($ispause))$ispause = 1;
						$ispause = $ispause == 1 ? 2 :1;
						$model->setStatus($ispause);
					}
					$this->result = $file->update($model);
				} 				
			}
		}
		echo $this->encodeResult($this->result);
	}	
}